#ifndef __GPIO_H__
#define __GPIO_H__

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#if 0
GPIO的输出;
1,确认GPIO分组号,例如GPIO8-3(拍照),GPIO8-4(录像); 前面数字是组,后面是位,每组8个IO;
2,gpio8-3===> 8*8+3=67,  67就是该(gpio8-3)gpio的编号;
3,引出该管脚
    命令操作方式,echo 67 > /sys/class/gpio/export,
    编程方式:  system("echo 67 > /sys/class/gpio/export")
4,配置管脚输入输出,
    命令操作方式;echo  in/out > /sys/class/gpio/gpio67/direction ;         //in 输入， out输出，二选一
    编程方式; system("echo out > /sys/class/gpio/gpio67/direction")        //将管脚67配置成输出
              system("echo in > /sys/class/gpio/gpio67/direction")         //将管脚67配置成输入
5,gpio赋值;
    命令操作方式: echo 1 > /sys/class/gpio/gpio67/value;                    //赋值1输出
    编程方式; system("echo 1 > /sys/class/gpio/gpio67/value")              //赋值为0
#endif


#define GPIO_HDMI        20     //gpio2_4   HDMI-HPD
#define GPIO_UP          72     //gpio9_0   OSD上翻
#define GPIO_DOWN        73     //gpio9_1   OSD下翻
#define GPIO_LEFT        74     //gpio9_2   OSD向左
#define GPIO_RIGHT       75     //gpio9_3   OSD向右
#define GPIO_OK          76     //gpio9_4   OSD确认
#define GPIO_OSD_CTRL    78     //gpio9_6   OSD开启关闭
#define GPIO_PHOTO       67     //gpio8_3
#define GPIO_VIDEO       68     //gpio8_4

#define GPIO_RESERV01    67     //gpio8_3
#define GPIO_RESERV02    66     //gpio8_2
#define GPIO_RESERV03    65     //gpio8_1
#define GPIO_RESERV04    68     //gpio8_4
#define GPIO_RESERV05    6      //gpio0_6
#define GPIO_RESERV06    79     //gpio9_7
#define GPIO_RESERV07    89     //gpio11_1
#define GPIO_RESERV08    4      //gpio0_4
#define GPIO_RESERV09    5      //gpio0_5
#define GPIO_RESERV10    90     //gpio11_2
#define GPIO_RESERV11    80     //gpio10_0
#define GPIO_RESERV12    81     //gpio10_1
#define GPIO_LED_STROB   87     //gpio10_7

#define GPIO_MOTO_A      4      //gpio0_4  负压马达开关脚,
#define GPIO_MOTO_B      5      //gpio0_5  正压马达开关脚,
#define GPIO_BEEP        1      //gpio0_1  蜂鸣器


/*
//============================================================================================================
#define GPIO_HDMI        20       //gpio2_4   HDMI-HPD        IN-----------KEY[00]
#define GPIO_PHOTO       67       //gpio8_3   ISO-io1         IN-----------KEY[01]    KEY-A   拍照
#define GPIO_VIDEO       68       //gpio8_4   ISO-io4         IN-----------KEY[02]    KEY-B   录像
#define GPIO_UP          72       //gpio9_0   OSD_UP          IN-----------KEY[03]      
#define GPIO_DOWN        73       //gpio9_1   OSD_DOWN        IN-----------KEY[04]
#define GPIO_LEFT        74       //gpio9_2   OSD_LEFT        IN-----------KEY[05]
#define GPIO_RIGHT       75       //gpio9_3   OSD_RIGHT       IN-----------KEY[06]
#define GPIO_OK          76       //gpio9_4   OSD_OK          IN-----------KEY[07]
#define GPIO_OSD_CTRL    78       //gpio9_6   OSD-ON/OFF      IN-----------KEY[08] 

#define GPIO_MWB         66       //gpio8_2   ISO-io2         IN-----------KEY[09]    KEY-C   白平衡
#define GPIO_FREEZZ      65       //gpio8_1   ISO-io3         IN-----------KEY[10]    KEY-D   冻结 
#define GPIO_ZOOM        6        //gpio0_6   ISO-io5         IN-----------KEY[11]    KEY_E   缩放
#define GPIO_ISOPIN7     55       //gpio6_7   ISO-io7         IN-----------KEY[12]    Reserv  隔离区预留按键
#define GPIO_ISOPIN8     88       //gpio11_0  ISO-io8         IN-----------KEY[13]    Reserv  隔离区预留按键1.8V 
#define GPIO_EXT80       80       //gpio10_0  EXT_20PIN       IN-----------KEY[14]    Reserv  20PIN扩展口   
#define GPIO_EXT81       81       //gpio10_1  EXT_20PIN       IN-----------KEY[15]    Reserv  20PIN扩展口
//============================================================================================================
#define GPIO_LED_STROB   87       //gpio10_7                  OUT                     横流源芯片使能脚
#define GPIO_ISOPIN6     64       //gpio8_0                   OUT                     ISO_IO6   
#define GPIO_MOTO_A      79       //gpio9_7                   OUT                     负压马达开关脚,
#define GPIO_MOTO_B      5        //gpio0_5                   OUT                     正压马达开关脚,
#define GPIO_BEEP        1        //gpio0_1                   OUT                     蜂鸣器
//============================================================================================================
*/



//============================================================================================================
int gpio_export(int pin);
int gpio_unexport(int pin);
//dir: 0-->IN, 1-->OUT
int gpio_direction(int pin, int dir);
//value: 0-->LOW, 1-->HIGH
int gpio_write(int pin, int value);
//============================================================================================================
int gpio_read(int pin);

//============================================================================================================
// none         表示引脚为输入，不是中断引脚
// rising       表示引脚为中断输入，上升沿触发
// falling      表示引脚为中断输入，下降沿触发
// both         表示引脚为中断输入，边沿触发
// 0-->none, 1-->rising, 2-->falling, 3-->both
//============================================================================================================
int gpio_edge(int pin, int edge);

#endif

